<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Plivo\RestClient;
use Illuminate\Support\Facades\DB;

class PlivoServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap services.
     *
     * @return void
     */
    public function boot()
    {

    }

    /**
     * Register services.
     *
     * @return void
     */
    public function register()
    {

        $res = DB::table('phone_settings')->where('status',1)->first();
        if($res && $res->type == 'plivo'){
            $auth_id = $res->account;
            $auth_token = $res->auth_token;

            $this->app->singleton(RestClient::class, function ($app) use($auth_id,$auth_token){
                return new RestClient( $auth_id, $auth_token);
            });
            $this->app->alias(RestClient::class, 'Plivo');
        }

    }
}
